package org.example;

import cn.clj1.*;
import cn.clj1.cell.CljCell;
import org.junit.Test;

import java.util.Hashtable;

public class MyClj_1_case {

    public static MyClojureReader getReader(String txt)
    {
        CljLinesFromString myIInput = new CljLinesFromString(txt);
        CljCharIterator myCharIterator = new CljCharIterator(myIInput);
        CljLexer lexer = new CljLexer(myCharIterator);
        MyClojureReader myLispReader = new MyClojureReader(lexer);
        return myLispReader;
    }
    
    @Test
    public void test_2() throws Exception {

        //MyClojureReader myLispReader = getReader("(defn my_add [x y] (+ y x))");
        MyClojureReader myLispReader = getReader("(defn my_add ([x y z] (+ y x z)) ([x y] (+ y x)))");
//        MyClojureReader myLispReader = getReader("(defn add \n" +
//                "    ([a c & b] (+ a c (apply * b))) \n" +
//                "    ([a b] (+ a b)))");
        CljCell myCell = myLispReader.getExpression();
        //CljResult rs = myClojureInterp.eval(myCell, new Hashtable<String, CljResult>(), new CljResult());
        MyClojureInterp.eval(myCell, new Hashtable<String, CljCell>(), null, new CljCell());
        myLispReader = getReader("(my_add 1 2.3 4)");
        //myLispReader = getReader("(add 1 2.3 4 5)");
        myCell = myLispReader.getExpression();
        CljCell rs = MyClojureInterp.eval(myCell, new Hashtable<String, CljCell>(), null, new CljCell());
        System.out.println(rs.getCell().toString());
    }
}
